﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AdministratorHelper
{
    static class Program
    {
        private static MainForm mainForm = null;
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.ApplicationExit += Application_ApplicationExit;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            WindowsIdentity id = WindowsIdentity.GetCurrent();
            //if (!AdminProcHelper.IsInRole(id))
            //{
            //    AdminProcHelper.RunElevated("AdministratorHelper.exe");
            //    Application.Exit();
            //}

            MainForm form = new MainForm();
            mainForm = form;
            Application.Run(form);
        }

        private static void Application_ApplicationExit(object sender, EventArgs e)
        {
            if (mainForm != null&&!mainForm.IsDisposed)
            {
                HotKeyHelper.UnregisterHotKey(mainForm.Handle, 1001);

            }
        }
    }
}
